﻿Imports System.Data.Entity
Imports HSPElections1.Models

Namespace HSPElections1
    Public Class VoteNumsController
        Inherits System.Web.Mvc.Controller

        Private db As VoteNumsContext = New VoteNumsContext

        '
        ' GET: /VoteNums/

        Function Index() As ViewResult
            Return View(db.VoteNums.ToList())
        End Function

        '
        ' GET: /VoteNums/Details/5

        Function Details(id As Integer) As ViewResult
            Dim votenum As VoteNum = db.VoteNums.Find(id)
            Return View(votenum)
        End Function

        '
        ' GET: /VoteNums/Create

        Function Create As ViewResult
            return View()
        End Function

        '
        ' POST: /VoteNums/Create

        <HttpPost()>
        Function Create(votenum As VoteNum) As ActionResult
            If ModelState.IsValid Then
                db.VoteNums.Add(votenum)
                db.SaveChanges()
                Return RedirectToAction("Index")
            End If

            Return View(votenum)
        End Function
        
        '
        ' GET: /VoteNums/Edit/5
 
        Function Edit(id As Integer) As ViewResult
            Dim votenum As VoteNum = db.VoteNums.Find(id)
            Return View(votenum)
        End Function

        '
        ' POST: /VoteNums/Edit/5

        <HttpPost()>
        Function Edit(votenum As VoteNum) As ActionResult
            If ModelState.IsValid Then
                db.Entry(votenum).State = EntityState.Modified
                db.SaveChanges()
                Return RedirectToAction("Index")
            End If

            Return View(votenum)
        End Function

        '
        ' GET: /VoteNums/Delete/5
 
        Function Delete(id As Integer) As ViewResult
            Dim votenum As VoteNum = db.VoteNums.Find(id)
            Return View(votenum)
        End Function

        '
        ' POST: /VoteNums/Delete/5

        <HttpPost()>
        <ActionName("Delete")>
        Function DeleteConfirmed(id As Integer) As RedirectToRouteResult
            Dim votenum As VoteNum = db.VoteNums.Find(id)
            db.VoteNums.Remove(votenum)
            db.SaveChanges()
            Return RedirectToAction("Index")
        End Function

        Protected Overrides Sub Dispose(disposing As Boolean)
            db.Dispose()
            MyBase.Dispose(disposing)
        End Sub
        Function MakeVote() As ActionResult
            Dim newVote As New MakeNumVote
            Dim newballet As List(Of Integer) = newVote.createVote()
            Dim i As Integer = 1
            For Each numbers In newballet
                If i = 1 Then
                    If numbers = 0 Then
                        Dim res = db.VoteNums.Find(1)
                        res.President = res.President + 1
                    ElseIf numbers = 1 Then
                        Dim res = db.VoteNums.Find(2)
                        res.President = res.President + 1
                    ElseIf numbers = 2 Then
                        Dim res = db.VoteNums.Find(3)
                        res.President = res.President + 1
                    ElseIf numbers = 3 Then
                        Dim res = db.VoteNums.Find(4)
                        res.President = res.President + 1
                    ElseIf numbers = 4 Then
                        Dim res = db.VoteNums.Find(5)
                        res.President = res.President + 1
                    End If
                ElseIf i = 2 Then
                    If numbers = 0 Then
                        Dim res = db.VoteNums.Find(1)
                        res.VicePresident = res.VicePresident + 1
                    ElseIf numbers = 1 Then
                        Dim res = db.VoteNums.Find(2)
                        res.VicePresident = res.VicePresident + 1
                    ElseIf numbers = 2 Then
                        Dim res = db.VoteNums.Find(3)
                        res.VicePresident = res.VicePresident + 1
                    ElseIf numbers = 3 Then
                        Dim res = db.VoteNums.Find(4)
                        res.VicePresident = res.VicePresident + 1
                    ElseIf numbers = 4 Then
                        Dim res = db.VoteNums.Find(5)
                        res.VicePresident = res.VicePresident + 1
                    End If
                ElseIf i = 3 Then
                    If numbers = 0 Then
                        Dim res = db.VoteNums.Find(1)
                        res.Secretary = res.Secretary + 1
                    ElseIf numbers = 1 Then
                        Dim res = db.VoteNums.Find(2)
                        res.Secretary = res.Secretary + 1
                    ElseIf numbers = 2 Then
                        Dim res = db.VoteNums.Find(3)
                        res.Secretary = res.Secretary + 1
                    ElseIf numbers = 3 Then
                        Dim res = db.VoteNums.Find(4)
                        res.Secretary = res.Secretary + 1
                    ElseIf numbers = 4 Then
                        Dim res = db.VoteNums.Find(5)
                        res.Secretary = res.Secretary + 1
                    End If
                ElseIf i = 4 Then
                    If numbers = 0 Then
                        Dim res = db.VoteNums.Find(1)
                        res.Treasurer = res.Treasurer + 1
                    ElseIf numbers = 1 Then
                        Dim res = db.VoteNums.Find(2)
                        res.Treasurer = res.Treasurer + 1
                    ElseIf numbers = 2 Then
                        Dim res = db.VoteNums.Find(3)
                        res.Treasurer = res.Treasurer + 1
                    ElseIf numbers = 3 Then
                        Dim res = db.VoteNums.Find(4)
                        res.Treasurer = res.Treasurer + 1
                    ElseIf numbers = 4 Then
                        Dim res = db.VoteNums.Find(5)
                        res.Treasurer = res.Treasurer + 1
                    End If
                ElseIf i = 5 Then
                    If numbers = 0 Then
                        Dim res = db.VoteNums.Find(1)
                        res.SergeantAtArms = res.SergeantAtArms + 1
                    ElseIf numbers = 1 Then
                        Dim res = db.VoteNums.Find(2)
                        res.SergeantAtArms = res.SergeantAtArms + 1
                    ElseIf numbers = 2 Then
                        Dim res = db.VoteNums.Find(3)
                        res.SergeantAtArms = res.SergeantAtArms + 1
                    ElseIf numbers = 3 Then
                        Dim res = db.VoteNums.Find(4)
                        res.SergeantAtArms = res.SergeantAtArms + 1
                    ElseIf numbers = 4 Then
                        Dim res = db.VoteNums.Find(5)
                        res.SergeantAtArms = res.SergeantAtArms + 1
                    End If
                End If
                db.SaveChanges()
                i = i + 1
            Next
            Return RedirectToAction("Index")
        End Function
    End Class

End Namespace